﻿<UserControl x:Class="Demos.Convexhull.ContenedorPuntosUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" Name="contenedor"
             xmlns:Local="clr-namespace:Demos.Convexhull"
             d:DesignHeight="300" d:DesignWidth="300" SizeChanged="UserControlSizeChanged">
    <UserControl.Resources>
        <DataTemplate DataType="{x:Type Local:Punto}">
            <Ellipse Fill="{Binding Color}" Height="{Binding Altura}" Width="{Binding Anchura}"/>
        </DataTemplate>

        <DataTemplate DataType="{x:Type Local:Raya}">
            <Line X1="{Binding X1}" Y1="{Binding Y1}"
                  X2="{Binding X2}" Y2="{Binding Y2}"
                  Stroke="Red" StrokeThickness="1" Name="raya">
                <Line.Triggers>
                    <EventTrigger RoutedEvent="Line.Loaded">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation From="{Binding ElementName=raya, Path=X1}" 
                                                 To="{Binding ElementName=raya, Path=X2}" 
                                                 Duration="0:0:0.2"
                                                             Storyboard.TargetName="raya"
                                                             Storyboard.TargetProperty="(X2)"/>
                                <DoubleAnimation From="{Binding ElementName=raya, Path=Y1}" 
                                                 To="{Binding ElementName=raya, Path=Y2}" 
                                                 Duration="0:0:0.2"
                                                             Storyboard.TargetName="raya"
                                                             Storyboard.TargetProperty="(Y2)"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Line.Triggers>
            </Line>
        </DataTemplate>
    </UserControl.Resources>
    <Grid Name="grid">
        <ItemsControl ItemsSource="{Binding ElementName=contenedor, Path=ContenidoVisual}" BorderBrush="Transparent">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas Background="Transparent" MouseLeftButtonDown="CanvasMouseLeftButtonDown"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemContainerStyle>
                <Style>
                    <Setter Property="Canvas.Left" Value="{Binding X}" />
                    <Setter Property="Canvas.Top" Value="{Binding Y}" />
                </Style>
            </ItemsControl.ItemContainerStyle>
        </ItemsControl>
    </Grid>
</UserControl>
